/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package App;

import javax.swing.JOptionPane;

/**
 *
 * @author Ricardo
 */
public class interface_IMC extends javax.swing.JFrame {

    /**
     * Creates new form interface_IMC
     */
    public interface_IMC() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbSexo = new javax.swing.ButtonGroup();
        jlNomeCompleto = new javax.swing.JLabel();
        jtNomeCompleto = new javax.swing.JTextField();
        jlSexo = new javax.swing.JLabel();
        jrbMasculino = new javax.swing.JRadioButton();
        jrbFeminino = new javax.swing.JRadioButton();
        jlIdade = new javax.swing.JLabel();
        jtIdade = new javax.swing.JTextField();
        jlPeso = new javax.swing.JLabel();
        jlAltura = new javax.swing.JLabel();
        jtPeso = new javax.swing.JTextField();
        jtAltura = new javax.swing.JTextField();
        jbResultado = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlNomeCompleto.setText("Nome completo");

        jtNomeCompleto.setToolTipText("Digite seu nome");
        jtNomeCompleto.setMaximumSize(new java.awt.Dimension(2, 2));
        jtNomeCompleto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtNomeCompletoFocusLost(evt);
            }
        });
        jtNomeCompleto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtNomeCompletoKeyReleased(evt);
            }
        });

        jlSexo.setText("Sexo");

        jbSexo.add(jrbMasculino);
        jrbMasculino.setText("Masculino");

        jbSexo.add(jrbFeminino);
        jrbFeminino.setText("Feminino");

        jlIdade.setText("Idade");

        jtIdade.setToolTipText("Digite sua idade");

        jlPeso.setText("Peso");

        jlAltura.setText("Altura");

        jtPeso.setToolTipText("Digite seu peso");

        jtAltura.setToolTipText("Digite sua altura");

        jbResultado.setText("Resultado");
        jbResultado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbResultadoActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial Black", 2, 18)); // NOI18N
        jLabel1.setText("Cálculo de IMC");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jlNomeCompleto)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtNomeCompleto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jlSexo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbMasculino)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jrbFeminino)
                                .addGap(18, 18, 18)
                                .addComponent(jlIdade)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtIdade, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jbResultado)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jlPeso)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jtPeso, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jlAltura)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtAltura, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlNomeCompleto)
                    .addComponent(jtNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlSexo)
                    .addComponent(jrbMasculino)
                    .addComponent(jrbFeminino)
                    .addComponent(jlIdade)
                    .addComponent(jtIdade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlPeso)
                    .addComponent(jtPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlAltura)
                    .addComponent(jtAltura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbResultado)
                .addContainerGap(105, Short.MAX_VALUE))
        );

        jtNomeCompleto.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbResultadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbResultadoActionPerformed
        String campoDoFoco = "";
        boolean tudoPreenchido = true;
        if (jtNomeCompleto.getText().isEmpty()){
            campoDoFoco = jlNomeCompleto.getText();
            jtNomeCompleto.grabFocus();
        }
        
        
        if (tudoPreenchido == true){
            double massa  = Double.valueOf(jtPeso.getText());
            double altura = Double.valueOf(jtAltura.getText());
            double imc = massa/(altura*altura);
        
            if (imc <= 18.5){
                //System.out.println("Abaixo do Peso.");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está Abaixo do Peso");
            }
            if ((imc >= 18.6) && (imc <= 24.9)){
                //System.out.println("Saudável.");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está Saudável");
            }
            if ((imc >= 25.0) && (imc <= 29.9)){
                //System.out.println("Sobrepeso");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está com Sobrepeso");
            }
            if ((imc >= 30.0) && (imc <= 34.9)){
                //System.out.println("Obesidade Grau I");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está com Obesidade Grau I");
            }
            if ((imc >= 35.0) && (imc <= 39.9)){
                //System.out.println("Oberidade Grau II (severa)");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está com Obesidade Grau II (severa)");
            }
            if (imc >= 40.0){
                //System.out.println("Obesidade Grau III (mórbida)");
                JOptionPane.showMessageDialog(null, jtNomeCompleto.getText() + ", você está com Obesidade Grau III (mórbida)");
            }
        }else{
            JOptionPane.showMessageDialog(null, "O campo "+campoDoFoco+" não está preenchido, favor preenchê-lo!");
            
        }
    }//GEN-LAST:event_jbResultadoActionPerformed

    private void jtNomeCompletoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtNomeCompletoKeyReleased
        if (jtNomeCompleto.getText().length() > 100)
        {
            JOptionPane.showMessageDialog(null, "Atenção, nome acima de100 caracteres!");
            jbResultado.setEnabled(false);
            return;
        }else
        {
            jbResultado.setEnabled(true);
        }
    }//GEN-LAST:event_jtNomeCompletoKeyReleased

    private void jtNomeCompletoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtNomeCompletoFocusLost
        String s;
        s = jtNomeCompleto.getText();
        for (int i = 0; i <= jtNomeCompleto.getText().length(); i++){
        if (s.substring(i, i) == "A")
            JOptionPane.showMessageDialog(null, "deu a");
    }
    }//GEN-LAST:event_jtNomeCompletoFocusLost

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(interface_IMC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(interface_IMC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(interface_IMC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(interface_IMC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new interface_IMC().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jbResultado;
    private javax.swing.ButtonGroup jbSexo;
    private javax.swing.JLabel jlAltura;
    private javax.swing.JLabel jlIdade;
    private javax.swing.JLabel jlNomeCompleto;
    private javax.swing.JLabel jlPeso;
    private javax.swing.JLabel jlSexo;
    private javax.swing.JRadioButton jrbFeminino;
    private javax.swing.JRadioButton jrbMasculino;
    private javax.swing.JTextField jtAltura;
    private javax.swing.JTextField jtIdade;
    private javax.swing.JTextField jtNomeCompleto;
    private javax.swing.JTextField jtPeso;
    // End of variables declaration//GEN-END:variables
}
